function [q,sim_m]=smd(theta,est_m,b_param_sims,w_param_sims,b_error_sims,w_error_sims,b_Omega,w_Omega,W,nobeta,nosigma)

R=size(b_param_sims,2);
moments=zeros(length(est_m),R);

parfor r=1:R
   ests=make_ests(theta,[b_param_sims(:,r),w_param_sims(:,r)],[b_error_sims(:,r),w_error_sims(:,r)],b_Omega,w_Omega); 
   moments(:,r)=get_m(ests,W,nobeta,nosigma);
end

sim_m=mean(moments,2);

q=(est_m-sim_m)'*(est_m-sim_m);